package com.ciri.ssm.controller;

import com.ciri.ssm.entity.Users;
import com.ciri.ssm.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户表(Users)表控制层
 *
 * @author makejava
 * @since 2024-05-07 17:41:25
 */
@RestController
@RequestMapping("users")
public class UsersController {
    /**
     * 服务对象
     */
    @Autowired
    private UsersService usersService;


//    @GetMapping
//    public ResponseEntity<Page<Users>> queryByPage(Users users, PageRequest pageRequest) {
//        return ResponseEntity.ok(this.usersService.queryByPage(users, pageRequest));
//    }
    @RequestMapping(value = "/getlist", method = RequestMethod.GET)
    public List<Users> list() {
        return usersService.selectAll();
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
  //  @GetMapping("{id}")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseEntity<Users> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.usersService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param users 实体
     * @return 新增结果
     */
  //  @PostMapping
    public ResponseEntity<Users> add(Users users) {
        return ResponseEntity.ok(this.usersService.insert(users));
    }

    /**
     * 编辑数据
     *
     * @param users 实体
     * @return 编辑结果
     */
   // @PutMapping
    public ResponseEntity<Users> edit(Users users) {
        return ResponseEntity.ok(this.usersService.update(users));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
   // @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.usersService.deleteById(id));
    }

}

